package com.rabbitmq.demo.ttl;

import org.springframework.amqp.core.*;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Profile;

@Profile("ttl")
@Configuration
public class RabbitMQConfig {



    @Bean
    public DirectExchange directExchange(){
        return new DirectExchange("ttl");
    }

    @Bean
    public Queue queue() {
        return new Queue("ttl.queue");
    }

    @Bean
    public Queue ttlQueue() {
        Queue ttlQueue = new Queue("ttlQueue");
        ttlQueue.addArgument("x-message-ttl",2000);
        return ttlQueue;
    }

    @Bean
    public Binding binding(DirectExchange direct,
                             Queue queue) {
        return BindingBuilder.bind(queue)
                .to(direct).withQueueName();
    }

    @Bean
    public Binding binding1(DirectExchange direct,
                           Queue ttlQueue) {
        return BindingBuilder.bind(ttlQueue)
                .to(direct).withQueueName();
    }

    @Profile("sender")
    @Bean
    public Sender sender(){
        return new Sender();
    }
}
